package db

import (
	"ginfast/api/mall"
	"ginfast/api/system"
	"ginfast/api/weixin"
	"ginfast/configs"
	"ginfast/pkg/dao"
)

type Options struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

func Run() error {
	var o Options
	if err := configs.GViper.UnmarshalKey("sql", &o); err != nil {
		return err
	}
	db, err := dao.NewGormV2(o.Name, o.Address)
	if err != nil {
		return err
	}
	db.AutoMigrate(system.Models()...)
	db.AutoMigrate(weixin.Models()...)
	db.AutoMigrate(mall.Models()...)
	return nil
}
